<template>
  <div class="ListItem">
    <van-empty
      class="listItem-Show"
      v-show="listItemShow"
      image="search"
      description="找不到关键词"
    />
    <div
      v-for="item in searchList"
      :key="item.id"
      @click="GetItem(item.click_type, item.id, item.name)"
    >
      <van-icon name="search" color="#ccc" />
      {{ item.name }}
    </div>
  </div>
</template>

<script>
export default {
  name: "ListItem",
  props: ["searchList"],
  data() {
    return {
      inputVal: "",
      listItemShow: false,
    };
  },
  methods: {
    GetItem(click_type, id, itemName) {
      // console.log(click_type, id, itemName);
      // data_id=263&is_correct=1&page=1&click_type=content&keyword=实践乌托邦：无限人生书单第11季
      this.inputVal = itemName;
      this.$router.push({
        path: "/search/ItemView",
        query: {
          click_type: click_type,
          itemId: id,
          itemName: itemName,
        },
      });
      console.log("发送搜索文字", this.inputVal);
      this.$bus.$emit("inputVal", this.inputVal);
    },
  },
  watch: {
    searchList(newVal) {
      if (this.searchList) {
        if (newVal.length == 0) {
          this.listItemShow = true;
        } else {
          this.listItemShow = false;
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.ListItem {
  width: 100vw;
  position: absolute;
  left: 0;
  padding: 0.625rem 1.25rem;
  box-sizing: border-box;
  background-color: #fff;
  box-shadow: var(--boxsizi);
  border-radius: 0.5rem;
  z-index: 1;

  div {
    font-size: 0.875rem;
    padding: 0.875rem 0.625rem;
  }
}
</style>